package cn.dengta.webapp.im.form;

import cn.dengta.common.context.I18N;
import cn.dengta.common.validator.Form;
import cn.dengta.common.validator.ValidateError;
import cn.dengta.context.model.UserFormI18nKey;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;
import me.codeplayer.util.Assert;
import org.apache.commons.lang3.StringUtils;

@Getter
@Setter
@Accessors(chain = true)
public class GroupForm implements Form {

	/** 群名称 */
	private String name;
	/** 群图标 */
	private String icon;
	/** 加群模式：0=不用验证；1=需要验证；2=不允许任何人加入 */
	private Integer joinMode;
	/** 简介 */
	private String intro;
	/** 群id */
	private Long groupId;

	@Override
	public void validate() {
		if (groupId == null) {
			I18N.assertTrue(icon != null, I18N.msg(ValidateError.required, I18N.msg(UserFormI18nKey.AVATAR_CERT_FORM_AVATAR)));
			Assert.isTrue(!StringUtils.isEmpty(name) && joinMode != null);
			I18N.assertTrue(name.length() <= 60, I18N.msg(ValidateError.size_string_max_invalid, name, 60));
		} else {
			Assert.isTrue(!(StringUtils.isEmpty(name) && StringUtils.isEmpty(intro) && StringUtils.isEmpty(icon)));
		}
	}

}
